/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MassSetterDialog.java
 *
 * Created on Apr 25, 2011, 12:37:32 PM
 */
package it.kirys.rilego.gui;

import it.kirys.rilego.engine.loaders.imagesources.SourceRotation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Point;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

/**
 *
 * @author kirys
 */
public class MassSetterDialog extends javax.swing.JDialog {

	boolean okPressed = false;

	public boolean isOkPressed() {
		return okPressed;
	}

	/** Creates new form MassSetterDialog */
	public MassSetterDialog(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
		okPressed = false;
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      ButtonsPanel = new javax.swing.JPanel();
      OkButton = new javax.swing.JButton();
      CancelButton = new javax.swing.JButton();
      introLabel = new javax.swing.JLabel();
      rotationLabel = new javax.swing.JLabel();
      RotationCombo = new javax.swing.JComboBox();
      SplitCheckBox = new javax.swing.JCheckBox();

      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

      OkButton.setText("Ok");
      OkButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            OkButtonActionPerformed(evt);
         }
      });

      CancelButton.setText("Cancel");
      CancelButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            CancelButtonActionPerformed(evt);
         }
      });

      javax.swing.GroupLayout ButtonsPanelLayout = new javax.swing.GroupLayout(ButtonsPanel);
      ButtonsPanel.setLayout(ButtonsPanelLayout);
      ButtonsPanelLayout.setHorizontalGroup(
         ButtonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ButtonsPanelLayout.createSequentialGroup()
            .addContainerGap(289, Short.MAX_VALUE)
            .addComponent(OkButton)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(CancelButton)
            .addContainerGap())
      );
      ButtonsPanelLayout.setVerticalGroup(
         ButtonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ButtonsPanelLayout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(ButtonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(CancelButton)
               .addComponent(OkButton))
            .addContainerGap())
      );

      introLabel.setText("Select the option you want to apply to selected images");

      rotationLabel.setLabelFor(RotationCombo);
      rotationLabel.setText("Rotation:");

      RotationCombo.setModel(new DefaultComboBoxModel(SourceRotation.values()));

      SplitCheckBox.setText("Split");

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(ButtonsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(introLabel)
               .addGroup(layout.createSequentialGroup()
                  .addGap(12, 12, 12)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(SplitCheckBox)
                     .addGroup(layout.createSequentialGroup()
                        .addComponent(rotationLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(RotationCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
            .addContainerGap(79, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(introLabel)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(rotationLabel)
               .addComponent(RotationCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(SplitCheckBox)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
            .addComponent(ButtonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      );

      pack();
   }// </editor-fold>//GEN-END:initComponents

	public void showDialog() {
		int x;
		int y;

		// Find out our parent 
		Container myParent = getParent();
		Point topLeft = myParent.getLocationOnScreen();
		Dimension parentSize = myParent.getSize();

		Dimension mySize = getSize();

		if (parentSize.width > mySize.width) {
			x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
		} else {
			x = topLeft.x;
		}

		if (parentSize.height > mySize.height) {
			y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
		} else {
			y = topLeft.y;
		}

		setLocation(x, y);
		setVisible(true);
	}

	void cancelCommand() {
		okPressed = false;
		setVisible(false);
	}

	void okCommand() {
		okPressed = true;
		setVisible(false);
	}

	public boolean isSplit() {
		return SplitCheckBox.isSelected();
	}

	public SourceRotation getRotation() {
		Object ro = RotationCombo.getSelectedItem();
		if (ro instanceof SourceRotation) {
			return (SourceRotation) ro;
		} else {
			return SourceRotation.NoRotation;
		}
	}
	 private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelButtonActionPerformed
		 cancelCommand();
	 }//GEN-LAST:event_CancelButtonActionPerformed

	 private void OkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OkButtonActionPerformed
		 okCommand();
	 }//GEN-LAST:event_OkButtonActionPerformed

   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JPanel ButtonsPanel;
   private javax.swing.JButton CancelButton;
   private javax.swing.JButton OkButton;
   private javax.swing.JComboBox RotationCombo;
   private javax.swing.JCheckBox SplitCheckBox;
   private javax.swing.JLabel introLabel;
   private javax.swing.JLabel rotationLabel;
   // End of variables declaration//GEN-END:variables
}
